$(function(){
	var modifyInfoRecord={};
	var browseRecord={};
	var detailId=queryString('detailId');//取得？后的值
	var detailTime="";
	//获取信息修改记录
	getInfoRecord(detailId);
	getInformationFlow(detailId);
	$("#goback").click(function(){
		window.history.back();
	})
	
	//请求信息详细数据
	requestDetail(detailId);//请求数据
	$("#flowbtn").click(function(){
		$("#flowmodel").modal("show");
	});
	$(document).on('click','.modifyDetailInfo',function(){
		var recordId = $(this).attr("data-id");
		var time=$(this).attr("data-time");
		var infoId=detailId;
		getInfoDetailByModifyRecord(recordId,infoId,time);
	});
	//请求详细的修改之前的信息数据
	function getInfoDetailByModifyRecord(recordId,infoId,time){
//		getDetailModifyRecord
		var url="getDetailModifyRecord.do";//向后台请求数据id
		var modifyRecordDetail;
		YuXi.util.post(url,{recordId:recordId,infoId:infoId},function(data){
			if(data.status){
				
				modifyRecordDetail=data.object;
				
				if($.trim($(".reSearchSource").text())!=$.trim(modifyRecordDetail.informationSourceNames)){
					$(".modifySource").show();
					var html=time+"修改前的信息渠道:";
					$(".modifySource label").html("");
					$(".modifySource span").html("");
					$(".modifySource label").append(html);
					$(".modifySource span").append(modifyRecordDetail.informationSourceNames);
					
				}
				if($.trim($(".sele").text())!=$.trim(modifyRecordDetail.safetyPortNames)){
					$(".modifyPort").show();
					var html=time+"修改前的安全分口:";
					$(".modifyPort label").html("");
					$(".modifyPort span").html("");
					$(".modifyPort label").append(html);
					$(".modifyPort span").append(modifyRecordDetail.safetyPortNames);
					
				}
				if($.trim($(".pes").text())!=$.trim(modifyRecordDetail.informationClassificationNames)){
					$(".modifyPes").show();
					var html=time+"修改前的重要分级:";
					$(".modifyPes label").html("");
					$(".modifyPes span").html("");
					$(".modifyPes label").append(html);
					$(".modifyPes span").append(modifyRecordDetail.informationClassificationNames);
					
				}
				if($.trim($(".sort").text())!=$.trim(modifyRecordDetail.informationSortNames)){
					$(".modifySort").show();
					var html=time+"修改前的分类:";
					(".modifySort label").html("");
					$(".modifySort span").html("");
					$(".modifySort label").append(html);
					$(".modifySort span").append(modifyRecordDetail.informationSortNames);
					
				}
				if($.trim($(".label1").text())!=$.trim(modifyRecordDetail.inputPerSonNames)){
					$(".modifyPerson").show();
					var html=time+"修改前的参与人:";
					$(".modifyPerson label").html("");
					$(".modifyPerson span").html("");
					$(".modifyPerson label").append(html);
					$(".modifyPerson span").append(modifyRecordDetail.inputPerSonNames);
					
				}
				
				if($.trim($("#valProfile").text())!=$.trim(modifyRecordDetail.informationProfile)){
					$(".modifyProfile").show();
					var html=time+"修改前的信息简介:";
					$(".modifyProfile label").html("");
					$(".modifyProfile p").html("");
					$(".modifyProfile label").append(html);
					$(".modifyProfile p").append(modifyRecordDetail.informationProfile);
					
				}
				if($.trim($("#valContent").text())!=$.trim(modifyRecordDetail.informationProfile)){
					$(".modifyContent").show();
					var html=time+"修改前的信息内容:";
					$(".modifyContent label").html("");
					$(".modifyContent p").html("");
					$(".modifyContent label").append(html);
					$(".modifyContent p").append(modifyRecordDetail.informationProfile);
					
				}
				if($.trim($("#valMeasure").text())!=$.trim(modifyRecordDetail.informationProfile)){
					$(".modifyMeasure").show();
					var html=time+"修改前的信息措施:";
					$(".modifyMeasure label").html("");
					$(".modifyMeasure p").html("");
					$(".modifyMeasure label").append(html);
					$(".modifyMeasure p").append(modifyRecordDetail.informationProfile);
					
				}
				if($.trim($("#valStandard").text())!=$.trim(modifyRecordDetail.informationProfile)){
					$(".modifyStandard").show();
					var html=time+"修改前的信息标准:";
					$(".modifyStandard label").html("");
					$(".modifyStandard p").html("");
					$(".modifyStandard label").append(html);
					$(".modifyStandard p").append(modifyRecordDetail.informationProfile);
					
				}
			}
		},function(){
			
		});
	}
	$(document).on('click','#moreModifyRecord',function(){
		if($(this).text()=="查看更多"){
			$("#moreModifyRecord").text("收起");
			for(var i=4;i<20;i++){
				
				var date =(modifyInfoRecord[i].time)*1;
				date=new Date(date);
				var year =date.getFullYear();
				var month=date.getMonth()+1;
				var day=date.getDate();
				var hours=date.getHours();
				var minure=date.getMinutes();
				var detailtime=year+"年"+month+"月"+day+"日"+hours+"时"+minure+"分";
				if(modifyInfoRecord[i].doType==5){
					var html='<li class="list-group-item modifyDetailInfo" data-time='+detailtime+' data-id='+modifyInfoRecord[i].id+'>'+month+"月"+day+"日"+hours+"时"+" "+modifyInfoRecord[i].name+modifyInfoRecord[i].doRemark+'</li>';
					$("#moreModifyRecord").before(html);
				}else{
					var html='<li class="list-group-item"  >'+month+"月"+day+"日"+hours+"时"+" "+modifyInfoRecord[i].name+modifyInfoRecord[i].doRemark+'</li>';
					$("#moreModifyRecord").before(html);
				}
				
				
			}
		}else{
			$(".modifyRecord").html("");
			for(var i=0;i<4;i++){
				var date =(modifyInfoRecord[i].time)*1;
				date=new Date(date);
				var year =date.getFullYear();
				var month=date.getMonth()+1;
				var day=date.getDate();
				var hours=date.getHours();
				var minure=date.getMinutes();
				var detailtime=year+"年"+month+"月"+day+"日"+hours+"时"+minure+"分";
				if(modifyInfoRecord[i].doType==5){
					var html='<li class="list-group-item modifyDetailInfo" data-time='+detailtime+' data-id='+modifyInfoRecord[i].id+'>'+month+"月"+day+"日"+hours+"时"+" "+modifyInfoRecord[i].name+modifyInfoRecord[i].doRemark+'</li>';
					$(".modifyRecord").append(html);
				}else{
					var html='<li class="list-group-item">'+month+"月"+day+"日"+hours+"时"+" "+modifyInfoRecord[i].name+modifyInfoRecord[i].doRemark+'</li>';
					$(".modifyRecord").append(html);
				}
				
			}
			$(".modifyRecord"). append('<li class="list-group-item text-center"  style="padding:4px 15px;color:#347AB7;" id="moreModifyRecord">查看更多</li>');
		}
		
	});
	$(document).on('click','#moreBrowseRecord',function(){
		if($(this).text()=="查看更多"){
			$("#moreBrowseRecord").text("收起");
			for(var i=4;i<12;i++){
				var time = YuXi.getTime.get(browseRecord[i].browseTime);
				var html='<li class="list-group-item">'+time+" "+browseRecord[i].userName+'浏览了点评记录</li>';
				$("#moreBrowseRecord").before(html);
				
			}
		}else{
			$(".CommentRecordBrowse").html("");
			for(var i=0;i<4;i++){
				var time = YuXi.getTime.get(browseRecord[i].browseTime);
				var html='<li class="list-group-item">'+time+" "+browseRecord[i].userName+'浏览了点评记录</li>';
				$(".CommentRecordBrowse").append(html);
			}
			$(".CommentRecordBrowse"). append('<li class="list-group-item text-center"  style="padding:4px 15px;color:#347AB7;" id="moreBrowseRecord">查看更多</li>');
		}
		
	});
//正则取链接传来的数据
function queryString(key)
{
    var regex_str = "^.+\\?.*?\\b"+ key +"=(.*?)(?:(?=&)|$|#)";
    var regex = new RegExp(regex_str,"i");
    var url = window.location.toString();
    if(regex.test(url)) return RegExp.$1;
    return undefined;
}
//根据id向后台请求数据详情
function requestDetail(id)
{
	var url="getUserInformationById.do";//向后台请求数据id
	var object={}
	var soure=[];
	var personName=[];
	var dataid={informationId:id};
	YuXi.util.get(url,dataid,function(data){
		object=data.object;
		
		source=object.informationSourceNames;
		//**************************************************12.10***************************
			$(".userNameIn").html(object.userName);
		//**************************************************12.10***************************
		var pname=object.inputPerSonNames;
		pname=pname.substr(1);
		pname=pname.substring(0,pname.length-1);
		personName=pname;

		$(".reSearchSource ").append(source);
		$(".label1").append(personName);
		$(".infoBelong").html(object.prisonName);
		addOption(".sele",object.safetyPortNames);
		addOption(".pes",object.informationClassificationNames);
		addOption(".sort",object.informationSortNames);
		$("#valProfile").html(object.informationProfile);//简介
		$("#valStandard").html(object.standard);//标准
		$("#valMeasure").html(object.mesure);//措施
		$("#valContent").html(object.informationConternt);//内容
		//显示任务派遣情况
		if(object.flowId>=6){
			$(".taskTable").show();
			getTaskDispatch(id);
		}
		//获取点评记录
		if(object.flowId>=9){
			$("#commentRecord").show();
			getCommentRecord(id);
		}else{
			$("#commentRecord").show();
			getInputCommentRecord(id);
		}
//		//获取评价记录
//		if(object.flowId>=10){
//			$("#evaluationRecord").show();
//			getEvaluationRecord(id);
//		}
		if(object.flowId>=10){
			$("#CommentRecordBrowse").show();
			getCommentBrowseRecord(id);
			setTimeout(function(){
				addCommentRecorBrowse(id);
			},1100)
		}
		try{
			var appendix=object.appendix.substring(1,object.appendix.length-1);
			
			appendix=appendix.split(",");
			YuXi.appendix.get(appendix);
		}catch(error){
			
		}
	},function(){
		//console.log("数据请求失败");
	})
}

function addCommentRecorBrowse(id){
	var url="addCommentRecorBrowse.do";
	var infoId={infoId:id};
	var flag=0;
	var userId=$(".nav-userInfo").attr("data-userId");
	var recordId;
	
	for(var i=0;i<browseRecord.length;i++){
		if(browseRecord[i].userId==userId){
			
			recordId=browseRecord[i].id;
			flag=1;
			break;
		}
	}

	
	if(flag==1){
		url="modifyCommentRecorBrowse.do";
		infoId={infoId:id,id:recordId};
	}else{
		url="addCommentRecorBrowse.do";
		infoId={infoId:id};
	}
	YuXi.util.get(url,infoId,function(data){
		if(data.status){
			
			
			
		}
	},function(){
		
	});
}

//获取修改信息记录
function getCommentBrowseRecord(id){
	var url="getCommentBrowseByInfoId.do";
	var infoId={infoId:id};
	var object={};
	YuXi.util.get(url,infoId,function(data){
		if(data.status){
			object=data.object;
			browseRecord=object;
			$(".CommentRecordBrowse").html("");
			$(".browse-title").html("点评记录浏览列表("+browseRecord.length+"次)");
			if(object.length>4){
				for(var i=0;i<4;i++){
					var time = YuXi.getTime.get(object[i].browseTime);
					
					var html='<li class="list-group-item" >'+time+" "+object[i].userName+'浏览了点评记录</li>';
					$(".CommentRecordBrowse"). append(html);
				}
				$(".CommentRecordBrowse"). append('<li class="list-group-item text-center"  style="padding:4px 15px;color:#347AB7;" id="moreBrowseRecord">查看更多</li>');
			}else{
				for(var i=0;i<object.length;i++){
					var time = YuXi.getTime.get(object[i].browseTime);
					var html='<li class="list-group-item">'+time+" "+object[i].userName+'浏览了点评记录</li>';
					$(".CommentRecordBrowse").append(html);
				}
			}
			
		}else{
			
		}
	},function(){
		
	});
}

	//获取修改信息记录
	function getInfoRecord(id){
		var url="getOperationByInfoId.do";
		var infoId={infoId:id};
		var object={};
		YuXi.util.get(url,infoId,function(data){
			if(data.status){
				object=data.object;
				modifyInfoRecord=object;
				
				$(".modifyRecord").html("");
				if(object.length>4){
				
					for(var i=0;i<4;i++){
						var date =(object[i].time)*1;
						date=new Date(date);
						var year =date.getFullYear();
						var month=date.getMonth()+1;
						var day=date.getDate();
						var hours=date.getHours();
						var minure=date.getMinutes();
						var detailtime=year+"年"+month+"月"+day+"日"+hours+"时"+minure+"分";
						if(modifyInfoRecord[i].doType==5){
							var html='<li class="list-group-item modifyDetailInfo" data-time='+detailtime+' data-id='+modifyInfoRecord[i].id+'>'+month+"月"+day+"日"+hours+"时"+" "+object[i].name+object[i].doRemark+'</li>'
							$(".modifyRecord"). append(html);
						}else{
							var html='<li class="list-group-item">'+month+"月"+day+"日"+hours+"时"+" "+object[i].name+object[i].doRemark+'</li>'
							$(".modifyRecord"). append(html);
						}
						
					}
					$(".modifyRecord"). append('<li class="list-group-item text-center"  style="padding:4px 15px;color:#347AB7;" id="moreModifyRecord">查看更多</li>');
				}else{
					for(var i=0;i<object.length;i++){
						var date =(object[i].time)*1;
						date=new Date(date);
						var year =date.getFullYear();
						var month=date.getMonth()+1;
						var day=date.getDate();
						var hours=date.getHours();
						var minure=date.getMinutes();
						
						var detailtime=year+"年"+month+"月"+day+"日"+hours+"时"+minure+"分";
						if(modifyInfoRecord[i].doType==5){
							var html='<li class="list-group-item modifyDetailInfo" data-time='+detailtime+' data-id='+modifyInfoRecord[i].id+'>'+month+"月"+day+"日"+hours+"时"+" "+object[i].name+object[i].doRemark+'</li>';
							$(".modifyRecord").append(html);
						}else{
							var html='<li class="list-group-item">'+month+"月"+day+"日"+hours+"时"+" "+object[i].name+object[i].doRemark+'</li>';
							$(".modifyRecord").append(html);
						}
						
					}
				}
				
			}else{
				
			}
		},function(){
			
		});
	}
	
	
	
	//获取点评记录
	function getCommentRecord(id){
		var url="getCommentRecordByInfoId.do";
		var infoId={infoId:id};
		var object={};
		YuXi.util.get(url,infoId,function(data){
			if(data.status){
				object=data.object;
				commentRecord=object;
				$(".commentRecord").html("");
				$("#commentRecord").show();
				var html='<li class="list-group-item">'+"信息录入和收集质量：<span style='color:blue'>"+object.informationQualityName+'</span></li>'
				$(".commentRecord"). append(html);
				html='<li class="list-group-item">'+"录入和收集点评："+object.content+'</li>'
				$(".commentRecord"). append(html);
				html='<li class="list-group-item">'+"任务完成情况：<span style='color:blue'>"+object.taskCompletionName+'</span></li>'
				$(".commentRecord"). append(html);
				if(object.completeContent==undefined){
					object.completeContent=" ";
				}
				html='<li class="list-group-item">'+"完成情况点评："+object.completeContent+'</li>'
				$(".commentRecord"). append(html);
			}else{
			}
		},function(){
			
		});
	}
	//获取点评记录
	function getInputCommentRecord(id){
		var url="getCommentRecordByInfoId.do";
		var infoId={infoId:id};
		var object={};
		YuXi.util.get(url,infoId,function(data){
			if(data.status){
				object=data.object;
				commentRecord=object;
				$(".commentRecord").html("");
				$("#commentRecord").show();
				var html='<li class="list-group-item">'+"信息录入和收集质量：<span style='color:blue'>"+object.informationQualityName+'</span></li>'
				$(".commentRecord"). append(html);
				html='<li class="list-group-item">'+"录入和收集点评："+object.content+'</li>'
				$(".commentRecord"). append(html);
			}else{
				$("#commentRecord").hide();
			}
		},function(){
			
		});
	}
	
//	function getEvaluationRecord(id){
//		var url="getEvaluationRecordByInfoId.do";
//		var infoId={infoId:id};
//		var object={};
//		YuXi.util.get(url,infoId,function(data){
//			if(data.status){
//				object=data.object;
//				commentRecord=object;
//				$(".evaluationRecord").html("");
//				$("#evaluationRecord").show();
//				var html='<li class="list-group-item">'+"信息评价内容："+object.content+'</li>'
//				$(".evaluationRecord").append(html);
//			}else{
//				
//			}
//		},function(){
//			
//		});
//	}
	//获取任务派遣记录
	function getTaskDispatch(id){
		var url="getTaskDispatchByInfoId.do";
		var infoId={infoId:id};
		var object={};
		YuXi.util.get(url,infoId,function(data){
			if(data.status){
				object=data.object;
				for (var i = 0; i < object.length; i++) {
					var endTime="";
					var taskTime="长期";
					if(object[i].endTime!=0){
						endTime=new Date(object[i].endTime);
						var y=endTime.getFullYear() + '年';
						var m=(endTime.getMonth()+1)+'月';
						var d=endTime.getDate()+'日';
						endTime=y+m+d;
					}
					
					if(object[i].taskTime==3502800000000){
						taskTime="长期";
					}else{
						var time=new Date(object[i].taskTime);
						var y=time.getFullYear() + '年';
						var m=(time.getMonth()+1)+'月';
						var d=time.getDate()+'日';
						taskTime=y+m+d;
					}
					
					if(object[i].remark==undefined){
						object[i].remark="";
					}
					var  taskCompletion ;
					if(object[i].taskCompletion==null||object[i].taskCompletion==undefined){
						taskCompletion="";
					}else{
						taskCompletion=object[i].taskCompletion;
					}
					
					var html = "<tr ><td style='border:none;'>" + object[i].personDispatchName + "</td>" +
					"<td style='border:none;'>" + object[i].perSonLiableName + "</td>" +
					"<td style='border:none;'>" + taskTime + "</td>" +
					"<td style='border:none;'>" + object[i].remark + "</td>" +
					"<td style='border:none;'>" + taskCompletion+ "</td>" +
					"<td style='border:none;'>" +endTime  + "</td>" +
 					"</tr>";
					$("#tablebody").append(html);
				}
			}
		},function(){
			
		});
	}
	function getInformationFlow(id){
		var url="getInformationFlowByInfoId.do";
		var infoId={infoId:id};
		var object={};
		YuXi.util.get(url,infoId,function(data){
			if(data.status){
				object=data.object;
				var flow;
				
				for (var i = 0; i < object.length; i++) {
					if(object[i].lastFlowId==1){
						flow="信息管理";
					}
					if(object[i].lastFlowId==3){
						flow="复核";
					}
					if(object[i].lastFlowId==2){
						flow="初审";
					}
					if(object[i].lastFlowId==4){
						flow="审核";
					}
					
					var time = YuXi.getTime.get(object[i].createTime);
					
					if(object[i].remark==undefined){
						object[i].remark="";
					}
					var html = "<tr ><td style='border:none;'>" + object[i].userName + "</td>" +
					"<td style='border:none;'>" +time  + "</td>" +
					"<td style='border:none;'>" + object[i].operation + "</td>" +
					"<td style='border:none;'>" + object[i].remark + "</td>" +
					"<td style='border:none;'>" +flow  + "</td>" +
 					"</tr>";
					$("#tbody").append(html);
				}
			}
		},function(){
			
		});
	}
	function addOption(className,value){
		var html= value;
		$(className).append(html);
	}

});